{extend name="public:layout" /}
{block name="title"}添加{$moudleName}{/block}
{block name="head"}{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li>
                    <i class="fa fa-hand-o-right"></i>
                    <a href="{:url('index',['mid'=>$Request.param.mid,'cid'=>$Request.param.cid,'tpl'=>'index_spend'])}">结算单列表</a>
                </li>
                <li class="active">结算单</li>
            </ol>
        </div>
        <div class="ibox-content">
            <h1 class="text-center">
                出车方：{$info.btype_out.company}-{$info.btype_out.title}({$info.btype_out.btype_phone})
            </h1>
            <form method="post" class="form-horizontal" id="form" action="/system/logic.order/spenddo.html" onkeydown="if(event.keyCode==13){return false;}">
				<input type="hidden" name="aid" value="{$info.aid}" />
				<input type="hidden" name="mid" value="{$info.mid}" />
                <input type="hidden" name="title" value="{$info.title}" />
                <input type="hidden" name="car_sn" value="{$info.car_sn}" />
                <legend>费用报销</legend>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">带回客户款</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="带回客户款" id="m1" onkeyup="calcSjMoney();" value="0" datatype="*" />
                    </div>
                    <label class="col-sm-2 control-label Validform_label">司机预借款</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="司机预借款" id="m2" onkeyup="calcSjMoney();" value="{$info['sj_pre_money']}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">插单费用</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="插单费用" id="c1" onkeyup="calcSjMoney();" value="0" datatype="*" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">加油费</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="加油费" id="n1" onkeyup="calcSjMoney();" name="order_fuel" value="{$info['order_fuel']}" datatype="*" />
                    </div>
                    <label class="col-sm-2 control-label Validform_label">加油升数</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="升数" name="order_l" value="{$info['order_l']}" datatype="*" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">过路费</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="过路费" id="n2" onkeyup="calcSjMoney();" name="order_tolls" value="{$info['order_tolls']}" datatype="*" />
                    </div>
                    <label class="col-sm-2 control-label Validform_label">停车费</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="停车费" id="n3" onkeyup="calcSjMoney();" name="order_stop" value="{$info['order_stop']}" datatype="*" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">服务费</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="服务费" id="n4" onkeyup="calcSjMoney();" name="order_service" value="{$info['order_service']}" datatype="*" />
                    </div>
                    <label class="col-sm-2 control-label Validform_label">食宿</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="食宿" id="n5" onkeyup="calcSjMoney();" name="order_eat" value="{$info['order_eat']}" datatype="*" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">其他费用</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="其他费用" id="n6" onkeyup="calcSjMoney();" name="order_other" value="{$info['order_other']}" datatype="*" />
                    </div>
                    <label class="col-sm-2 control-label Validform_label">结余</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="结余" id="y_money" name="order_bala" value="{$info['sj_pre_money']}" readonly datatype="*" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">始发里程</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="始发里程" name="order_start_mm" readonly value="{$info['order_start_mm']}" datatype="*" />
                    </div>
                    <label class="col-sm-2 control-label Validform_label">结束里程</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="结束里程" name="order_end_mm" readonly value="{$info['order_end_mm']}" datatype="*" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">行驶里程</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="行驶里程" readonly name="order_mileage" value="{$info['order_end_mm']-$info['order_start_mm']}" datatype="*" />
                    </div>
                    <label class="col-sm-2 control-label Validform_label">备注</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="结算备注" name="order_remark" value="{$info.order_remark}" />
                    </div>
                </div>
                <legend>客户费用</legend>
				<div class="form-group">
					<label class="col-sm-2 control-label Validform_label">结算方式</label>
                    <div class="col-sm-3" style="padding-left: 30px;">
                        <label class="radio-inline i-checks" style="margin-right: 40px;">
                        <input type='radio' name="order_pay_type" value="0" checked /> 现金
                        </label>
                        <label class="radio-inline i-checks">
                            <input type='radio' name="order_pay_type" value="1" /> 转账
                        </label>
                    </div>
				</div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">订单费用</label>
                    <div class="col-sm-3">
                        <input class="form-control calc" type="text" placeholder="车费" readonly="readonly" name="order_charge" value="{$info['order_charge']}" datatype="*" />
                    </div>
                    <label class="col-sm-2 control-label Validform_label">定金</label>
                    <div class="col-sm-3">
                        <input class="form-control calc" type="text" placeholder="定金" name="order_advance" value="{$info['order_advance']}" datatype="*" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">待收</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="待收" name="order_q" readonly value="0" datatype="*" />
                    </div>
                    <label class="col-sm-2 control-label Validform_label">优惠金额</label>
                    <div class="col-sm-3">
                        <input class="form-control" type="text" placeholder="请输入优惠金额" name="discount_money" value="0.00" datatype="*" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">本次收款</label>
                    <div class="col-sm-3">
                        <input class="form-control calc" type="text" placeholder="现收" name="order_pay" id="order_pay" value="{$info['order_pay']}" datatype="*" />
                        <span class="help-block m-b-none">输入司机带回金额后自动计入本次回款</span>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <button class="btn btn-primary" id="btnSub" type="button">保存</button>
                        <a href="{:url('index',['mid'=>$Request.param.mid])}" class="btn btn-white">取消</a>
                        <span id="validError"></span>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        iCheck();
        formatDate();
        ajaxSubForm('#btnSub');
        getOrderq();
        $('.calc').keyup(function () {
            getOrderq();
        });
    });
    //计算司机费用
    function calcSjMoney() {
        var m1=parseFloat($('#m1').val()); //带回金额
        var m2=parseFloat($('#m2').val()); //预借金额
        var c1=parseFloat($('#c1').val()); //插单金额
        var n1=parseFloat($('#n1').val());
        var n2=parseFloat($('#n2').val());
        var n3=parseFloat($('#n3').val());
        var n4=parseFloat($('#n4').val());
        var n5=parseFloat($('#n5').val());
        var n6=parseFloat($('#n6').val());
        var y_money = (m1+m2-n1-n2-n3-n4-n5-n6+c1).toFixed(2); //结余
        $('#y_money').val(y_money);
        $('#order_pay').val(m1);
        getOrderq();
    }
    //待收费用
    function getOrderq() {
        var order_charge=parseFloat($("input[name='order_charge']").val());
        var order_advance=parseFloat($("input[name='order_advance']").val());
        var order_pay=parseFloat($("input[name='order_pay']").val());
        var order_q = order_charge-order_advance-order_pay;
        if(order_q<0){
            alert('收费金额计算错误！');
            return false;
        }
        $("input[name='order_q']").val(order_q.toFixed(2));
    }
    /*设置优惠金额，优惠金额不能大于待收金额*/
    $('input[name="discount_money"]').blur(function (){
        var discount_money=$('input[name="discount_money"]').val();
        var order_q=$('input[name="order_q"]').val();
        if (isNaN(discount_money)) {
            //inputDom.val(currentSku.mininum);
            alert('优惠金额必须为数字！');
            $('input[name="discount_money"]').val(0.00);
            return false;
        }
        if(parseFloat(discount_money)>parseFloat(order_q)){
            alert('优惠金额不能大于待收款项');
            $('input[name="discount_money"]').val(0.00);
            return false;
        }
        var number=parseFloat(order_q)-parseFloat(discount_money);
        $('input[name="order_q"]').val(number);

    })
</script>
{/block}